package com.atguigu.tingshu.album.client;

import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.cache.GuiguCache;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/***
 * 获取3级标题
 */
@RestController
@RequestMapping("/client/album/category")
public class BaseCategoryViewController {
    @Autowired
    BaseCategoryService baseCategoryService;

    /**
     * 根据3级id获取一级二级标题
     * @param category3Id
     * @return
     */
    @GuiguCache(name = "getBaseCategoryView:")
    @GetMapping("/getBaseCategoryView/{category3Id}")
    public BaseCategoryView getBaseCategoryView(@PathVariable(value = "category3Id")Long category3Id){
        return baseCategoryService.getBaseCategoryView(category3Id);
    }

    /**
     * 根据一级分类id去查找三级分类
     * @param category1Id
     * @return
     */
    @GuiguCache(name = "getBaseCategory3List:")
    @GetMapping("/getBaseCategory3List/{category1Id}")
    public List<BaseCategory3> getBaseCategory3List(@PathVariable(value = "category1Id")Long category1Id){
        return (List<BaseCategory3>) baseCategoryService.findTopBaseCategory3(category1Id);
    }

}
